package com.tool.cn.java8;

import java.time.Clock;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * @Description:函数式编程实际应用 
 * @author wangzonghui
 * @date 2019年9月18日 下午4:21:03
 */
public class EarlyPrint {
	
	public static void main(String[] args) {
		
		//结合过滤
		List<String> names=Arrays.asList("jack","Jill","Nate","Kara","mo","ad");
		
		System.out.println(names.stream()
				.filter(name -> name.length()==4)
				.collect(Collectors.joining(",")));
		
		//创建线程
		new Thread(
			    () -> System.out.println("单线程实例!")
			).start();
		
		//提取集合
		List<String> other=names.stream()
				.filter(name -> name.length()==4)
				.map(name -> name.toUpperCase())
				.collect(Collectors.toList());
		other.forEach(one -> System.out.println(one));
		System.out.println();
		other.forEach(System.out::println);
		
		//null处理
		Optional<String> firstName=Optional.ofNullable(null); //.orElse(other)添加默认对象  .orElseGet(other)执行默认方法 
		System.out.println( "First Name is set? " + firstName.isPresent() ); 
		System.out.println( "First Name: " + firstName );
		System.out.println( firstName.map( s -> "Hey " + s + "!" ).orElse( "Hey Stranger!" ) );
		
		//时间 Clock时区时间
		Clock clock=Clock.systemUTC();
		System.out.println(clock.instant());
		System.out.println(clock.millis());
		
		LocalDateTime dateTime=LocalDateTime.now();
		System.out.println("时间："+dateTime);
		
		LocalDate date = LocalDate.now();
		LocalDate dateFromClock = LocalDate.now( clock );
		
		System.out.println(date);
		System.out.println(dateFromClock);
		
		LocalTime time = LocalTime.now();
		LocalTime timeFromClock = LocalTime.now( clock );
		
		System.out.println(time);
		System.out.println(timeFromClock);
		
		
	}

}
